import 'package:dio/dio.dart';
import 'package:get/get.dart';

import '../../http/api/api_service.dart';
import '../../http/retrofit_client.dart';
import '../../models/version.dart';
import '../../view_state/view_state.dart';
import '../../view_state/view_state_logic.dart';

class HomeController extends ViewStateLogic {
  var count = 0.obs; // 使用 obs 创建响应式变量
  final Rx<ViewState> viewState = ViewState().obs;
  late Rx<Version?> versionData = Version().obs;
  final ApiService apiService = Get.find();
  String _response = '';
  final Dio _dio = Dio();
  void increment() {
    count++;
  }

  void getVersion() async {
    Version? version = await apiService.getVersion();
    print("==$version");
    versionData.value = version;
    // update();
  }

  void getVersions() async {
    sendRequest(RetrofitClient.instance.apiService.getVersion(),
        showLoadingDialog: true, successCallback: (data) {
      print("==$data");
      versionData.value = data;
    });
  }

  void makeGetRequest() async {
    try {
      final response =
          await _dio.get('https://jsonplaceholder.typicode.com/posts/1');
      print(response.data);
    } catch (e) {
      _response = '请求失败: $e';
    }
  }
}
